package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "菜品管理相关接口")
@Slf4j
@RequestMapping("/admin/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    /***菜品分页查询
     *
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result pageDish(DishPageQueryDTO dishPageQueryDTO){
        return Result.success(dishService.dishPageQuery(dishPageQueryDTO));
    }

    /***新增菜品
     *
     * @param dishDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增菜品")
    public Result addDish(@RequestBody DishDTO dishDTO){

        dishService.addDish(dishDTO);
        return Result.success();
    }

    /***删除/批量删除菜品
     *
     * @param ids
     * @return
     */
    @DeleteMapping()
    @ApiOperation("删除/批量删除菜品")
    public Result deleteDish(@RequestParam List<Long> ids){
        dishService.deleteDish(ids);
        return Result.success();
    }

    /***根据菜品获取菜品和口味信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据菜品id返回菜品及口味信息")
    public Result getDishAndFlavorByDishId(@PathVariable("id") Long id){
        DishVO dishVO=dishService.getDishAndFlavorByDishId(id);
       return Result.success(dishVO);
    }

    /***修改菜品
     *
     * @param dishDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改菜品")
    public Result updateDishAndFlavor(@RequestBody DishDTO dishDTO){
        dishService.updateDishAndFlavor(dishDTO);
        return Result.success();
    }

    /***启用禁用菜品
     *
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("设置菜品启用禁用")
    public Result<Integer> starOrStopDish(@PathVariable Integer status,Long id){
        log.info("获取的数据:{}",status,id);
        int rows=dishService.updateStatus(status,id);
        log.info("shu:{}",rows);
        return Result.success(rows);
    }

}
